using System;

namespace StateManagement.Models {
  public class CartItem<T> where T : Product {
    internal readonly T Product;
    internal uint Quantity;
    public CartItem(T item, uint quantity = 1) {
      Product = item;
      Quantity = quantity;
    }
    public float SubTotal {
      get {
        return Quantity * Product.Price;
      }
    }
    public void Increase(uint n = 1) {
      Quantity += n;
    }
    public bool Decrease(uint n = 1) {
      if (n > Quantity) return false;
      Quantity -= n;
      return true;
    }
    override public string ToString() {
      return String.Format($"Code:{Product.Code}\t Quantity:{Quantity}");
    }
  }
}
